package com.fsc.comadapoc1.presentation.panels
{
	import com.fsc.comadapoc1.domain.PortfolioModel;
	import com.fsc.comadapoc1.entities.LiquidityReportRequest;
	import com.fsc.comadapoc1.events.LoadLiquidityExitFeesEvent;
	import com.fsc.comadapoc1.events.LoadLiquidityReportEvent;
	import com.fsc.comadapoc1.events.LoadPortfolioEvent;
	
	import flash.events.EventDispatcher;
	
	import mx.collections.Grouping;
	import mx.collections.GroupingCollection2;
	import mx.collections.GroupingField;
	import mx.collections.SummaryField2;
	import mx.collections.SummaryRow;
	import mx.events.FlexEvent;

	

	public class LiquidityReportResultsDisplayPanelPM extends EventDispatcher
	{
		[Bindable]
		[Inject]
		public var model:PortfolioModel;
		
		/** The datagrid state **/
		public const DATAGRID_STATE : String = "datagridDisplay";
		
		/** The chart state. **/
		public const CHART_STATE : String = "chartDisplay";
		
		[Bindable]
		public var myGC:GroupingCollection2 = new GroupingCollection2();
		
		private var _currentState:String = DATAGRID_STATE;
		
		/**
		 * Get the current state of the presentation model.
		 */
		[Bindable]
		public function get currentState() : String
		{
			return _currentState;
		}
		
		/**
		 * Sets the current state of the presentation model.
		 */
		public function set currentState( state:String ) : void
		{
			_currentState = state;	
		}
		
		

		[MessageHandler(selector="liquidityReportComplete")]
		public function liquidityReportCompleteHandler(event:LoadLiquidityReportEvent):void{
			refreshData();
		}
		
		public function liquidityReportDatagrid_creationCompleteHandler(event:FlexEvent):void
		{
			// TODO Auto-generated method stub
			refreshData();
		}
		
		protected function refreshData():void{
		
			var myG:Grouping = new Grouping();
			var myGF:GroupingField = new GroupingField();
			var myGF2:GroupingField = new GroupingField();
			
			myGF.name = "FundName";
			myGF2.name = "InterimPaymentDate";
			
			myG.fields = [myGF];
			myGC.grouping = myG;
	
			
			var mySF:SummaryField2 = new SummaryField2();
			var mySF1:SummaryField2 = new SummaryField2();
			var mySF2:SummaryField2 = new SummaryField2();
			var mySR:SummaryRow = new SummaryRow();
			
			mySR.summaryPlacement = "group";
			mySF.dataField = "BaseValue";
			mySF1.dataField = "InterimProceeds";
			mySF2.dataField = "FinalProceeds";
			//mySF1.dataField = "NoticeDate";
			//mySF.label = "summary";
			//mySF.summaryOperation = "COUNT";
			mySR.fields = [mySF,mySF1,mySF2];
			
			myGC.source = model.currentPortfolio.liquidityReport;
			
			myGF.summaries = [mySR];
			
			myGC.refresh();
	
		}
		
	
		

	}
}